<template>
  <view class="content">
    <view class="box">
      <mk-echart :options="options" :key="key"></mk-echart>
      <view class="yxts">
        <view class="progressText">
          <view class="toptitle" :style="{ fontSize: TitleSize }">{{ title }}</view>
          <view class="fontyut" :style="{ color: color }">{{ value }}</view>
          <view class="bfh" :style="{ textAlign: footerTitleAlign }">{{
            footerTitle
          }}</view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import MkEchart from "../../libs/index.vue";
export default {
  name: "mkround",
  components: {
    MkEchart,
  },
  props: {
    title: {
      type: String,
      default: "",
    },
    value: "",
    color: {
      type: String,
      default: "#FF2625",
    },
    max: {
      type: Number,
      default: 200,
    },
    TitleSize: {
      type: String,
      default: "30rpx",
    },
    footerTitle: {
      type: String,
      default: "%",
    },
    footerTitleAlign: {
      type: String,
      default: "right",
    }
  },
  watch: {
    value(val) {
      this.val = val;
      this.options.series[0].data[0].value = this.val;
    },
    color(val) {
      this.colorBak = val;
      this.setOptions();
    }
  },
  data() {
    return {
      key: new Date().getTime(),
      val: 0,
      colorBak: "#ffffff",
      options: {
        series: [
          {
            type: "gauge",
            startAngle: 230,
            endAngle: -50,
            min: 0,
            max: this.max,
            pointer: false,
            detail: false,
            axisLabel: false,
            axisLine: { show: false },
            progress: { show: true, width: 6, overlap: true, roundCap: true },
            splitLine: { show: false },
            axisTick: {
              distance: -8,
              length: 1,
              lineStyle: { width: 3, color: "#fff", cap: "round" },
            },
            data: [{ value: this.value, itemStyle: { color: this.color } }],
          },
        ],
      },
    };
  },
  methods: {
    //组装数据
    setOptions() {
      this.options.series = [];
      let serie = {
        type: "gauge",
        startAngle: 230,
        endAngle: -50,
        min: 0,
        max: this.max,
        pointer: false,
        detail: false,
        axisLabel: false,
        axisLine: { show: false },
        progress: { show: true, width: 6, overlap: true, roundCap: true },
        splitLine: { show: false },
        axisTick: {
          distance: -8,
          length: 1,
          lineStyle: { width: 3, color: "#fff", cap: "round" },
        },
        data: [{ value: this.val, itemStyle: { color: this.colorBak } }],
      };
      this.options.series[0] = serie;
    },
  },
};
</script>

<style lang="scss">
.content {
  flex-direction: column;
  justify-content: center;
  align-items: center;
  display: flex;
  .box {
    width: 360rpx;
    height: 360rpx;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    .yxts {
      position: absolute;
      .progressText {
        font-size: 28rpx;
        color: #ffffff;
        text-align: center;
        width: 130px;
        .fontyut {
          font-size: 122rpx;
          line-height: 102rpx;
          margin: 6rpx 0 16rpx 0;
        }
        .bfh {
          border-top: 2rpx solid #ffffff;
          font-size: 20rpx;
          width: 120rpx;
          padding-top: 12rpx;
          margin: 0 auto;
        }
      }
    }
  }
}
</style>
